import {connect} from 'react-redux';
import {setTitle} from './ui/actions';
import {setToken} from './token/actions';

const mapAllState2Props = (state, props) => {
    return {
        ...props,
        storeState: state,
    };
};
const asPropFun = (fun, dispatch) => {
    return (...args) => dispatch(fun(...args));
};
const mapAllAction2Props = (dispatch, props) => {
    return {
        ...props,
        actions: {
            setTitle: asPropFun(setTitle, dispatch),
            setToken: asPropFun(setToken, dispatch),
        }
    };
};

export const withStore = component => {
    return connect(mapAllState2Props, mapAllAction2Props)(component);
};
